package com.fx.service.impl;

import com.fx.mapper.UserMapper;
import com.fx.pojo.User;
import com.fx.service.UserService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Cacheable(value = "user",key = "'findList'")
    @Override
    public List<User> findList() {
        System.out.println("查数据库啦~~~~");
        return userMapper.selectList(null);
    }


    @CacheEvict(value = "user",key = "'findList'")
    @Override
    public int add(User user) {
        System.out.println("新增用户到数据库啦~~~~");
        return userMapper.insert(user);
    }

    @CacheEvict(value = "user",key = "'findList'")
    @Override
    public int update(User user) {
        System.out.println("修改用户到数据库啦~~~~");
        return userMapper.updateById(user);
    }


}
